#include "lua_print.h"
#include "lua_utils.h"
#include <string>

std::mutex lua_print::m_mutex;
static luaL_Reg lib_functions[] =
{
    { "print", &lua_print::print},
    { NULL, NULL}
};

void lua_print::initialize(lua_State* L, const char* lib_name)
{
    lua_newtable(L);

    luaL_Reg* fun_info = lib_functions;
    while (fun_info->func)
    {
        lua_pushcfunction(L, fun_info->func);
        lua_setfield(L, -2, fun_info->name);
        fun_info++;
    }
    lua_setfield(L, -2, lib_name);
}

void lua_print::uninitialize()
{

}

int lua_print::print(lua_State* L)
{
    //m_mutex.lock();
    lua_utils::print(L);
    //m_mutex.unlock();

    return 0;
}
